package com.hm.order.service;

import org.springframework.stereotype.Service;

import com.hm.common.common.CommonUtil;
import com.hm.common.exception.ServiceException;
import com.hm.order.mongo.def.OrderOperationStatu;
import com.hm.order.mongo.def.OrderOwner;
import com.hm.order.mongo.def.OrderStatusOperation;
import com.hm.order.share.service.OrderStatusEngineService;

/**
 * @author shishun.wang
 * @date 下午3:45:25 2016年7月21日
 * @version 1.0
 * @describe
 */
@Service
public class OrderStatusEngineServiceImpl implements OrderStatusEngineService {

	public OrderOperationStatu nextStatus(OrderOwner orderOwner, OrderOperationStatu currentOrderStatu,
			OrderStatusOperation operation) {
		if (CommonUtil.isEmpty(orderOwner, operation)) {
			throw ServiceException.warn("订单操作角色或者操作状态不允许为null");
		}
		if (operation.getOrderOwner() != orderOwner) {
			throw ServiceException.warn(orderOwner.getDesc() + "不能操作该订单");
		} else {
			if (currentOrderStatu != operation.getCurentStatu()) {
				throw ServiceException.warn(currentOrderStatu.desc() + "不支持" + operation.getCurentStatu().desc() + "操作");
			}
		}
		return operation.getNextOperationStatu();
	}
}
